<template>
  <section class="pagemaker-form-comp-val">
    <div v-if="_compVar.length == 0" class="empty">
      <div class="icon">
        <svg-icon icon-class="empty-icon" />
      </div>
    </div>
    <section v-else class="list">
      <el-table
        :data="_compVar"
        style="width: 90%;margin: 0 auto;"
      >
        <el-table-column
          label="名称"
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.name" disabled placeholder="请输入" />
          </template>
        </el-table-column>
        <el-table-column
          label="标识"
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.code" disabled placeholder="请输入" />
          </template>
        </el-table-column>
        <el-table-column
          label="默认值"
        >
          <template slot-scope="scope">
            <!--            <el-input v-model="scope.row.value"  @input="inputChange($event)" placeholder="请输入" />-->
            <el-select v-model="scope.row.value" :allow-create="true" :clearable="true" :filterable="true" :placeholder="'请输入'" style="width: 100%;" @change="handleChange">
              <el-option v-for="(item, index) in _pageVar" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </template>
        </el-table-column>
      </el-table>
    </section>
  </section>
</template>
<script>

export default {
  name: 'CompVar',
  inject: ['compVar', 'pageVar'],
  data() {
    return {
    }
  },
  computed: {
    _compVar() {
      const arr = this.compVar()
      return arr
    },
    _pageVar() {
      return this.pageVar()
    }
  },
  watch: {
    _compVar: {
      handler(val) {
        this.dispatch_event('page-compVar-change', val)
      },
      deep: true
    }
  },
  methods: {
    inputChange(e) {
      this.$forceUpdate()
    },

    setCheck(e) {
      let { value, required } = this
      if (this.option.override !== undefined) {
        this.option.override(this, value, this.list.length ? this.list : this.asyncList)
      }
      if (this.option.change !== undefined) {
        this.option.change(this, e)
      }
      let error = false; let errorMsg = ''
      if (value !== undefined && value !== null) {
        value = value + ''
      }
      if (required && !value) {
        error = true
        errorMsg = '必填选项不能为空'
      }
      this.error_ = error
      this.error_message_ = errorMsg
      this.fieldCheck()
    },

    handleChange(e) {
      this.setCheck(e)
      this.dispatch_event('filed-value-change', e)
    }
  }
}
</script>
<style lang="scss" scoped>
@import '@/styles/var.scss';
@import '@/styles/utility/position.scss';
@import '@/styles/utility/center.scss';
.pagemaker-form-comp-val {
  @include absolute();
  overflow: auto;
  .empty {
    line-height: 80px;
    @include center();
    padding: 20px 0 20px 0;
    pointer-events: none;
    color: $f3;
    .icon {
      height: 50px;
      width: 50px;
      font-size: 30px;
      background: $f8;
      border-radius: 50%;
      border: 1px solid $f6;
      @include center();
    }
  }
}
</style>
